﻿using System;
using System.Collections.Generic;
using Moq;
using Prompts.Prompting.ViewModels;
using Prompts.Prompting.ViewModels.Implementation;

namespace Test.Prompts.Infrastructure.Fakes
{
    internal class FakePromptsViewModelService
    {
        private readonly Mock<IPromptsViewModelService> _promptsViewModelService;
        private Action<IEnumerable<IPrompt>> _callBack;

        public FakePromptsViewModelService()
        {
            _promptsViewModelService = new Mock<IPromptsViewModelService>();
        }

        public IPromptsViewModelService Object
        {
            get { return _promptsViewModelService.Object; }
        }

        public void SetupGetPrompts(string reportName)
        {
            var setup = _promptsViewModelService
                .Setup(s => s.GetPromptViewModels(
                    reportName
                    , It.IsAny<Action<IEnumerable<IPrompt>>>()));

            setup.Callback<string, Action<IEnumerable<IPrompt>>>((n, c) =>
            {
                _callBack = c;
            });
        }

        public void ExecuteCallback(IEnumerable<IPrompt> prompts)
        {
            _callBack(prompts);
        }

        public void AssertNumberOfGetPrompts(string name, Times exactly)
        {
            _promptsViewModelService
                .Verify
                    (s => s.GetPromptViewModels(
                        name
                        , It.IsAny<Action<IEnumerable<IPrompt>>>())
                    , exactly);
        }

        public void AssertNumberOfCancels(string reportPath, Times times)
        {
            _promptsViewModelService.Verify(s => s.CancelGetPromptViewModels(reportPath), times);
        }

        public void RaiseErrorOccured(string errorMessage)
        {
            _promptsViewModelService.Raise(s => s.ErrorGettingPrompts += null
                , new ErrorGettingPromptsArgs(errorMessage));
        }
    }
}
